import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-12
 * Time: 20:44
 */
//https://leetcode.cn/problems/duplicate-zeros/
public class Test {
    public static void duplicateZeros(int[] arr) {
        int p1=0;
        int p2=0;
        while(p2<arr.length){
            if(arr[p1]==0){
                p2++;
                p2++;
                if(p2<arr.length){
                    p1++;
                }
            }
            else{
                p2++;
                if(p2<arr.length){
                    p1++;
                }
            }
        }
        p2--;
        if(p2==arr.length){
            p2--;
            p1--;
            arr[p2--]=0;
        }
        while(p2>=0){
            if(arr[p1]==0){
                arr[p2--]=0;
                arr[p2--]=0;
                p1--;
            }
            else{
                arr[p2--]=arr[p1--];
            }
        }
    }
    public static void main(String[] args) {
        int[] arr={0,0,0,0,0,0,0};
        duplicateZeros(arr);
        System.out.println(Arrays.toString(arr));
    }
}
